package com.dataart.productshop.dao.impl;

import com.dataart.productshop.dao.SubjectDao;
import com.dataart.productshop.model.boiko.informationsystem.Subject;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class SubjectDaoImpl extends BaseDaoImpl<Subject> implements SubjectDao{
    public SubjectDaoImpl() {
        super(Subject.class);
    }

    public void removeByName(String name){
        List<Subject> selected = getByName(name);
        if(selected != null){
            for (Subject subject : selected) {
                delete(subject.getId());
            }
        }
    }

    public List<Subject> getByName(String name){
        return createCriteria(Subject.class)
                .add(Restrictions.eq("name", name))
                .list();
    }
}
